package oppsa.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Map.Entry;
import java.util.TreeMap;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SortOrder;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.table.TableColumn;

import net.miginfocom.swing.MigLayout;
import oppsa.controller.Action;
import oppsa.controller.ActionType;
import oppsa.controller.ColumnManager;
import oppsa.controller.Comment;
import oppsa.controller.FormatData;
import oppsa.controller.Meeting;
import oppsa.controller.MeetingType;
import oppsa.controller.SSComponent;
import oppsa.controller.SubSystem;
import oppsa.controller.Translate;
import oppsa.controller.User;
import oppsa.model.ActionDB;
import oppsa.model.ActionTypeDB;
import oppsa.model.CommentDB;
import oppsa.model.MeetingDB;
import oppsa.model.MeetingTypeDB;
import oppsa.model.ProjectDB;
import oppsa.model.SSComponentDB;
import oppsa.model.SubsystemDB;
import oppsa.model.UserDB;
import oppsa.util.Constants;
import oppsa.util.Session;

import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.plaf.basic.CalendarHeaderHandler;
import org.jdesktop.swingx.plaf.basic.SpinningCalendarHeaderHandler;

//Variables
public class ActionDetailsView extends JXFrame {
	private static final long serialVersionUID = 1L;
	private JLabel textFieldActionID;
	private JTable tableComments;
	private JXDatePicker pickerStart;
	private JXDatePicker pickerReview;
	private SimpleDateFormat form;
	private JComboBox<String> comboBoxSubSystem;
	private JComboBox<String> comboBoxSSComponent;
	private JComboBox<String> comboBoxResponsible;
	private JComboBox<String> comboBoxActionType;
	private JComboBox<?> comboBoxState;
	private JComboBox<?> comboBoxPriority;
	private JXDatePicker openDate;
	private JXDatePicker closeDate;
	private JLabel LastModified;
	private TreeMap<Integer, String> responsibleMap;
	private TreeMap<Integer, String> subSystemMap;
	private TreeMap<Integer, String> ssComponentMap;
	private TreeMap<Integer, String> actionTypeMap;
	private TreeMap<Integer, String> MeetingTypeMap;
	private TreeMap<Integer, String> MeetingMap;	
	private Action currentAction = new Action();
	private JButton btnReturn;
	private HomeView hv;
	private boolean newAction;
	private JPanel panelActionDetails;
	private JButton btnCancel;
	private JLabel lblMeeting;
	private JLabel lblActionDescription;
	private JLabel lblSubSystem;
	private JLabel lblActionType;
	private JLabel lblInitialDueDate;
	private JLabel lblOpenDate;
	private JLabel lblCloseDate;
	private JLabel lblPriority;
	private JLabel lblState;
	private JLabel lblResponsible;
	private JLabel lblReviewDueDate;
	private JLabel lblLastModified;
	private JLabel lblComments;
	private JLabel lblAddComment;
	private JButton btnAddSubSystem;
	private JButton btnAddSSComponent;
	private JButton btnAddMeeting;

	private JButton btnAddOwner;
	private JButton btnAddActionType;
	private JScrollPane scrollPaneComments;
	private JPanel panelComments;
	private JTableModelComment modele;
	private JEditorPane editorPaneNewComment;
	private JComboBox<String> comboBoxResponsibleComment;
	private int sequenceAction;
	private MeetingDB listMeeting;
	private ActionDB listAction;
	private CommentDB listComment;
	private SSComponentDB listSSComponent;
	private UserDB listUser;
	private ActionTypeDB listActionType;
	private SubsystemDB listSubSystem;
	private Meeting currentMeeting;
	private Comment currentComment;
	private JLabel lblError;
	private JPanel panelTittle;
	private MeetingTypeDB listMeetingType;
	private JButton source;
	private ColumnManager cm;
	private int oldInterv=0;
	private int newInterv=0;
	
	private Translate t = new Translate();
//Initiation du détail des actions
	public ActionDetailsView(int sequenceAction, final boolean newAction, HomeView hv) {
		//Ajout des année dans le date picker
		UIManager.put(CalendarHeaderHandler.uiControllerID, SpinningCalendarHeaderHandler.class.getName());

		setIconImage(Toolkit.getDefaultToolkit().getImage(ActionDetailsView.class.getResource("/LOGO_FONCE.png")));
		getContentPane().setBackground(Color.WHITE);
		getRootPaneExt().getContentPane().setBackground(Color.WHITE);
		getRootPaneExt().setBackground(Color.WHITE);
		this.newAction = newAction;
		
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				if (newAction) {
					listAction = new ActionDB();
					listAction.deleteByActionID(textFieldActionID.getText());
				}
				setVisible(false);
				ActionDetailsView.this.hv.setEnabled(true);
				ActionDetailsView.this.hv.toFront();
			}
		});
		
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowIconified(WindowEvent arg0) {
				ActionDetailsView.this.hv.setExtendedState(JFrame.ICONIFIED);
			}
		});
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowDeiconified(WindowEvent arg0) {
				ActionDetailsView.this.hv.setExtendedState(JFrame.MAXIMIZED_BOTH);
			}
		});

		
		this.hv = hv;
		this.sequenceAction = sequenceAction;
		textFieldActionID = new JLabel(t.getLocalizedText("lblActionDetails"));
		btnCancel = new JButton("");
		btnReturn = new JButton("");
		editorPaneActionDescription = new JEditorPane();
		ActionDetailsView.this.addWindowListener( new WindowAdapter() {
		    @Override
			public void windowOpened( WindowEvent e ){
		    	editorPaneActionDescription.requestFocus();
		    	editorPaneActionDescription.setBorder(BorderFactory.createCompoundBorder(
		    			editorPaneActionDescription.getBorder(), 
		    	        BorderFactory.createEmptyBorder(5, 3, 5, 5)));
		    }
		}); 
		// Initialisation des maps
		subSystemMap = new TreeMap<Integer, String>();
		listSubSystem = new SubsystemDB();
		ssComponentMap = new TreeMap<Integer, String>();
		MeetingMap = new TreeMap<Integer, String>();
		listSSComponent = new SSComponentDB();
		actionTypeMap = new TreeMap<Integer, String>();
		MeetingTypeMap = new TreeMap<Integer, String>();
		listActionType = new ActionTypeDB();
		responsibleMap = new TreeMap<Integer, String>();
		listUser = new UserDB();
		scrollPaneComments = new JScrollPane();
		scrollPaneComments.setBorder(new MatteBorder(1, 1, 1, 1, Color.WHITE));
		scrollPaneComments.setBackground(Color.WHITE);
		panelComments = new JPanel();
		panelComments.setBorder(new MatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
		lblComments = new JLabel(t.getLocalizedText("lblComments"));
		modele = new JTableModelComment(this.sequenceAction);
		lblAddComment = new JLabel(t.getLocalizedText("lblAddComments"));
		editorPaneNewComment = new JEditorPane();
		comboBoxResponsibleComment = new JComboBox<String>();
		currentComment = new Comment();
		listComment = new CommentDB();
		listMeeting = new MeetingDB();
		
		// initialisation de la page
		init();
		updateFrame(this.sequenceAction);
	}


	private void init() {
		addWindowListener(closeWindow);
		setStartPosition(StartPosition.CenterInParent);
		setMinimumSize(new Dimension(800, 600));
		setMaximumSize(new Dimension(800, 600));
		setResizable(false);
		setPreferredSize(new Dimension(800, 600));
		setTitle(t.getLocalizedText("tlActionDetails"));
		
		scrollPaneTitle = new JScrollPane();
		scrollPaneTitle.setBorder(new MatteBorder(1, 1, 1, 1, Color.WHITE));
		scrollPaneTitle.setBackground(Color.WHITE);
		scrollPaneTitle.setPreferredSize(new Dimension(2, 57));
		getRootPaneExt().getContentPane().add(scrollPaneTitle, BorderLayout.NORTH);
		
		panelTittle = new JPanel();
		panelTittle.setBorder(new MatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));
		panelTittle.setBackground(new Color(50, 84, 210));
		scrollPaneTitle.setViewportView(panelTittle);
		panelTittle.setLayout(new MigLayout("", "[][grow][]", "[][]"));

		textFieldActionID.setFont(new Font("Tahoma", Font.BOLD, 16));
		textFieldActionID.setForeground(new Color(210, 210, 210));
		panelTittle.add(textFieldActionID, "cell 0 0, aligny top");

		btnCancel.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("Cancel"))));
		btnCancel.setBorder(null);
		btnCancel.addMouseListener(cancel);
		
		lblError = new JLabel((String) null);
		lblError.setForeground(Color.WHITE);
		panelTittle.add(lblError, "cell 1 0, center");
		
		panelTittle.add(btnCancel, "cell 4 0 4 2,alignx right");
		
		btnReturn.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("Validate"))));
		btnReturn.setBorder(null);
		btnReturn.addMouseListener(btnReturnAction);
		panelTittle.add(btnReturn, "cell 4 0 4 2");

		String[] comboStates = { t.getLocalizedText("lblStateOpened"),
				t.getLocalizedText("lblStateAssigned"), t.getLocalizedText("lblStateClosed"), t.getLocalizedText("lblStateAdjourned") };
		
		String[] comboPrio = { t.getLocalizedText("lblPriorityHigh"),
				t.getLocalizedText("lblPriorityMedium"), t.getLocalizedText("lblPriorityLow") };
		
		
		UIManager.put("TabbedPane.selected", Color.WHITE);
		UIManager.put("TabbedPane.contentAreaColor", Color.WHITE);
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBorder(new MatteBorder(1, 1, 1, 1, Color.WHITE));
		tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		tabbedPane.setBackground(Color.WHITE);
		getRootPaneExt().getContentPane().add(tabbedPane, BorderLayout.CENTER);
		panelActionDetails = new JPanel();

		lblActionDescription = new JLabel(t.getLocalizedText("lblActionDescription"));
		lblActionType = new JLabel(t.getLocalizedText("lblActionType"));
		comboBoxActionType = new JComboBox<String>();
		btnAddActionType = new JButton("");
		
		panelActionDetails.setBackground(Color.WHITE);
		panelActionDetails.setLayout(new MigLayout("", "[][120.00,grow][][200.00,grow]", "[][grow][][][][][]"));
		
		
		comboBoxMeetingType = new JComboBox<String>();
		comboBoxMeetingType.addItem("");
		lblMeetingType = new JLabel(t.getLocalizedText("lblMeetingType"));
		if (t.getCurrentLanguageString().equals("English")){
			comboBoxMeetingType.setPreferredSize(new Dimension(140, 22));
			comboBoxMeetingType.setMaximumSize(new Dimension(140, 22));
		}else{
			comboBoxMeetingType.setPreferredSize(new Dimension(120, 22));
			comboBoxMeetingType.setMaximumSize(new Dimension(120, 22));
		}
		comboBoxMeetingType.addActionListener(choseMeetingType);
		
		panelActionDetails.add(lblActionDescription, "cell 0 0,alignx left");
		
		comboBoxSubSystem = new JComboBox<String>();
		comboBoxSubSystem.addItem("");
		
		editorPaneActionDescription.setBorder(new LineBorder(Color.GRAY));
		panelActionDetails.add(editorPaneActionDescription, "cell 1 0 4 2,grow");
		if (t.getCurrentLanguageString().equals("English")){
			comboBoxSubSystem.setPreferredSize(new Dimension(140, 22));
			comboBoxSubSystem.setMaximumSize(new Dimension(140, 22));
		}else{
			comboBoxSubSystem.setPreferredSize(new Dimension(120, 22));
			comboBoxSubSystem.setMaximumSize(new Dimension(120, 22));
		}
		
		comboBoxSubSystem.addActionListener(choseSubSystem);
		
		lblMeeting = new JLabel(t.getLocalizedText("lblMeeting"));
		
		panelActionDetails.add(lblMeeting, "cell 2 3,alignx left");
		panelActionDetails.add(lblActionType, "cell 0 2,alignx left");
		comboBoxActionType.addItem("");
		comboBoxActionType.setPreferredSize(new Dimension(180, 22));
		comboBoxActionType.setMaximumSize(new Dimension(180, 22));
		panelActionDetails.add(comboBoxActionType, "flowx,cell 1 2,alignx left");
		
		lblSubSystem = new JLabel(t.getLocalizedText("lblSubSystem"));
		
		lblOpenDate = new JLabel(t.getLocalizedText("lblOpenDate"));
		lblOpenDate.setMinimumSize(new Dimension(130, 22));
		panelActionDetails.add(lblOpenDate, "cell 0 6");
		openDate = new JXDatePicker();

		openDate.getMonthView().setZoomable(true);
		panelActionDetails.add(openDate, "cell 1 6");
		
		
		panelActionDetails.add(lblSubSystem, "cell 2 4,alignx left");
		
		
		comboBoxSSComponent = new JComboBox<String>();
		
		if (t.getCurrentLanguageString().equals("English")){
			comboBoxSSComponent.setPreferredSize(new Dimension(140, 22));
			comboBoxSSComponent.setMaximumSize(new Dimension(140, 22));
		}else{
			comboBoxSSComponent.setPreferredSize(new Dimension(120, 22));
			comboBoxSSComponent.setMaximumSize(new Dimension(120, 22));
		}
		
		panelActionDetails.add(comboBoxSubSystem,"flowx,cell 3 4,alignx left");
		panelActionDetails.add(comboBoxSSComponent,"flowx,cell 3 4,alignx left");
		btnAddSSComponent = new JButton("");
		
		btnAddSSComponent.setIcon(new ImageIcon(getClass().getResource(
				t.getLocalizedText("PlusB"))));
		btnAddSSComponent.setBorder(null);
		btnAddSSComponent.addMouseListener(addSubSysComponent);
		panelActionDetails.add(btnAddSSComponent, "cell 3 4,alignx left");
		JSeparator trait = new JSeparator();
		trait.setPreferredSize(new Dimension(750,1));
		panelActionDetails.add(trait,"cell 0 5 5 5, aligny top");	
		form = new SimpleDateFormat("dd-MM-yyyy");
		lblInitialDueDate = new JLabel(t.getLocalizedText("lblInitialeDueDate"));
		lblInitialDueDate.setMinimumSize(new Dimension(130, 22));
		panelActionDetails.add(lblInitialDueDate, "cell 0 7 4 7,alignx left");
		
		pickerStart = new JXDatePicker();
		pickerStart.getMonthView().setZoomable(true);
		listAction = new ActionDB();
		pickerStart.getMonthView().setShowingWeekNumber(true);
		currentAction = listAction.selectBySeq(this.sequenceAction);

		//Préremplissage de la date initiale dans le datepicker
		if (!currentAction.getInitialDueDate().equals("")){
			try {
				pickerStart.setDate(FormatData.stringToDate(currentAction.getInitialDueDate()));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				System.err.println("Ops : "+ e.getMessage());
			}
		}
		//Préremplissage de la date initiale dans le datepicker
		if (!currentAction.getOpenDate().equals("")){
			try {
				openDate.setDate(FormatData.stringToDate(currentAction.getOpenDate()));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				System.err.println("Ops : "+ e.getMessage());
			}
		}		
			pickerStart.setPreferredSize(new Dimension(150, 22));
			pickerStart.setMaximumSize(new Dimension(150, 22));

			openDate.setPreferredSize(new Dimension(150, 22));
			openDate.setMaximumSize(new Dimension(150, 22));

		panelActionDetails.add(pickerStart, "cell 0 7 4 7,alignx left");
		
		lblReviewDueDate = new JLabel(t.getLocalizedText("lblReviewDueDate"));
		
		panelActionDetails.add(lblReviewDueDate, "cell 0 7 4 7,alignx left");
		
		pickerReview = new JXDatePicker();
		pickerReview.getMonthView().setZoomable(true);
		pickerReview.getMonthView().setShowingWeekNumber(true);
		if (!currentAction.getReviewedDueDate().equals("")){
		try {
			pickerReview.setDate(FormatData.stringToDate(currentAction.getReviewedDueDate()));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.err.println("Ops : "+ e.getMessage());
		}
		}
		
		pickerReview.setPreferredSize(new Dimension(150, 22));
		pickerReview.setMaximumSize(new Dimension(150, 22));

		
		panelActionDetails.add(pickerReview, "cell 0 7 4 7,alignx left");
		
		lblCloseDate = new JLabel(t.getLocalizedText("lblCloseDate"));
		
		panelActionDetails.add(lblCloseDate, "cell 0 7 4 7,alignx left");
		closeDate = new JXDatePicker();
		closeDate.getMonthView().setZoomable(true);
		closeDate.getMonthView().setShowingWeekNumber(true);
		listAction = new ActionDB();
		currentAction = listAction.selectBySeq(this.sequenceAction);
		if (newAction == false){
		if (!currentAction.getCloseDate().equals("")){
			try {
				closeDate.setDate(FormatData.stringToDate(currentAction.getCloseDate()));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				System.err.println("Ops : "+ e.getMessage());
			}
		}
		}
		

		closeDate.setPreferredSize(new Dimension(150, 22));
		closeDate.setMaximumSize(new Dimension(150, 22));

		panelActionDetails.add(closeDate, "cell 0 7 4 7,alignx left");
		
		comboBoxState = new JComboBox<Object>(comboStates);
		
		comboBoxState.setPreferredSize(new Dimension(220, 22));
		comboBoxState.setMaximumSize(new Dimension(220, 22));
		panelActionDetails.add(comboBoxState, "cell 1 3,alignx left");
		
				
				
		comboBoxResponsible = new JComboBox<String>();
		comboBoxResponsible.addItem("");
		if (t.getCurrentLanguageString().equals("English")){
		comboBoxResponsible.setPreferredSize(new Dimension(284, 22));
		comboBoxResponsible.setMaximumSize(new Dimension(284, 22));
		}else{
			comboBoxResponsible.setPreferredSize(new Dimension(244, 22));
			comboBoxResponsible.setMaximumSize(new Dimension(244, 22));
		}
		panelActionDetails.add(comboBoxResponsible,"flowx,cell 3 2,alignx left");
		
		btnAddOwner = new JButton("");
		
		btnAddOwner.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusB"))));
		btnAddOwner.setBorder(null);
		btnAddOwner.addMouseListener(addOwner);
		panelActionDetails.add(btnAddOwner, "cell 3 2,alignx left");
		
		lblLastModified = new JLabel(t.getLocalizedText("lblLastModified"));
		lblLastModified.setForeground(new Color(210, 210, 210));
		panelTittle.add(lblLastModified, "cell 0 1, aligny top");
		LastModified = new JLabel();
		LastModified.setForeground(new Color(210, 210, 210));
		panelTittle.add(LastModified, "cell 1 1");
		lblState = new JLabel(t.getLocalizedText("lblState"));
		
		panelActionDetails.add(lblState, "cell 0 3,alignx left");
		
		
		
		lblResponsible = new JLabel(t.getLocalizedText("lblResponsible"));
		
		panelActionDetails.add(lblResponsible, "cell 2 2,alignx left");
		
		lblPriority = new JLabel(t.getLocalizedText("lblPriority"));
		
		panelActionDetails.add(lblPriority, "cell 0 4,alignx left");
		
		btnAddActionType.setIcon(new ImageIcon(getClass().getResource(
				t.getLocalizedText("PlusB"))));
		btnAddActionType.setBorder(null);
		btnAddActionType.addMouseListener(addActionType);
		panelActionDetails.add(btnAddActionType, "cell 1 2");
		
		comboBoxPriority = new JComboBox<Object>(comboPrio);
		
		comboBoxPriority.setPreferredSize(new Dimension(220, 22));
		comboBoxPriority.setMaximumSize(new Dimension(220, 22));
		panelActionDetails.add(comboBoxPriority, "cell 1 4,alignx left");
		
		comboBoxMeeting = new JComboBox<String>();
		
		if (t.getCurrentLanguageString().equals("English")){
			comboBoxMeeting.setPreferredSize(new Dimension(140, 22));
			comboBoxMeeting.setMaximumSize(new Dimension(140, 22));
		}else{
			comboBoxMeeting.setPreferredSize(new Dimension(120, 22));
			comboBoxMeeting.setMaximumSize(new Dimension(120, 22));
		}
		panelActionDetails.add(comboBoxMeetingType, "cell 3 3");
		panelActionDetails.add(comboBoxMeeting, "cell 3 3");
		
		cm = new ColumnManager(true);
		
		btnAddMeeting = new JButton("");
		
		btnAddMeeting.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusB"))));
		btnAddMeeting.setBorder(null);
		btnAddMeeting.addMouseListener(addMeet);
		panelActionDetails.add(btnAddMeeting, "cell 3 3,alignx left");
		
		panelOptionalFields = new JPanel();
		panelOptionalFields.setBackground(Color.WHITE);
		panelOptionalFields.setLayout(null);
		
		JPanel panelOptionalFieldsExplanation = new JPanel();
		panelOptionalFieldsExplanation.setBackground(Color.WHITE);
		panelOptionalFieldsExplanation.setBounds(0, 0, 777, 46);
		panelOptionalFields.add(panelOptionalFieldsExplanation);
		panelOptionalFieldsExplanation.setLayout(new MigLayout("", "[grow]", "[39.00,grow]"));
		
		textAreaExplanation = new JTextArea(t.getLocalizedText("lblExplanationOptionalFiels"));
		textAreaExplanation.setFont(new Font("Tahoma", Font.BOLD, 12));
		textAreaExplanation.setLineWrap(true);//retour a la ligne
		textAreaExplanation.setWrapStyleWord(true);//empèche de couper les mots au retout a la ligne
		panelOptionalFieldsExplanation.add(textAreaExplanation, "cell 0 0,grow");
		
		panelOptionalFieldsDetail = new JPanel();
		panelOptionalFieldsDetail.setBounds(0, 45, 777, 290);
		panelOptionalFields.add(panelOptionalFieldsDetail);
		panelOptionalFieldsDetail.setBackground(Color.WHITE);
		panelOptionalFieldsDetail.setLayout(new MigLayout("", "[grow][grow][grow][grow][grow][grow]", "[28.00][28.00][28.00][28.00][28.00]"));
		
		//ajout des label optionnel text
		
		lblText1 = new JLabel(cm.GetColumn("text01").getName());						
		lblText2 = new JLabel(cm.GetColumn("text02").getName());						
		lblText3 = new JLabel(cm.GetColumn("text03").getName());						
		lblText4 = new JLabel(cm.GetColumn("text04").getName());						
		lblText5 = new JLabel(cm.GetColumn("text05").getName());
		

		lblDate1 = new JLabel(cm.GetColumn(Constants.DATE_1).getName());
		lblDate2 = new JLabel(cm.GetColumn(Constants.DATE_2).getName());
		lblDate3 = new JLabel(cm.GetColumn(Constants.DATE_3).getName());
		lblDate4 = new JLabel(cm.GetColumn(Constants.DATE_4).getName());
		lblDate5 = new JLabel(cm.GetColumn(Constants.DATE_5).getName());
		

		lblNumber1 = new JLabel(cm.GetColumn(Constants.NUMBER_1).getName());
		lblNumber2 = new JLabel(cm.GetColumn(Constants.NUMBER_2).getName());
		lblNumber3 = new JLabel(cm.GetColumn(Constants.NUMBER_3).getName());
		lblNumber4 = new JLabel(cm.GetColumn(Constants.NUMBER_4).getName());
		lblNumber5 = new JLabel(cm.GetColumn(Constants.NUMBER_5).getName());
		
		panelOptionalFieldsDetail.add(lblText1, "cell 0 0,alignx left");
		panelOptionalFieldsDetail.add(lblText2, "cell 0 1,alignx left");
		panelOptionalFieldsDetail.add(lblText3, "cell 0 2,alignx left");
		panelOptionalFieldsDetail.add(lblText4, "cell 0 3,alignx left");
		panelOptionalFieldsDetail.add(lblText5, "cell 0 4,alignx left");
		
		panelOptionalFieldsDetail.add(lblDate1, "cell 2 0,alignx left");						
		panelOptionalFieldsDetail.add(lblDate2, "cell 2 1,alignx left");						
		panelOptionalFieldsDetail.add(lblDate3, "cell 2 2,alignx left");						
		panelOptionalFieldsDetail.add(lblDate4, "cell 2 3,alignx left");						
		panelOptionalFieldsDetail.add(lblDate5, "cell 2 4,alignx left");
		
		panelOptionalFieldsDetail.add(lblNumber1, "cell 4 0,alignx left");					
		panelOptionalFieldsDetail.add(lblNumber2, "cell 4 1,alignx left");						
		panelOptionalFieldsDetail.add(lblNumber3, "cell 4 2,alignx left");						
		panelOptionalFieldsDetail.add(lblNumber4, "cell 4 3,alignx left");
		panelOptionalFieldsDetail.add(lblNumber5, "cell 4 4,alignx left");
		
		
		

		textFieldText1 = new JTextField();
		textFieldText2 = new JTextField();
		textFieldText3 = new JTextField();
		textFieldText4 = new JTextField();
		textFieldText5 = new JTextField();					
		
		textFieldDate1 = new JTextField();
		textFieldDate2 = new JTextField();
		textFieldDate3 = new JTextField();
		textFieldDate4 = new JTextField();
		textFieldDate5 = new JTextField();
		
		textFieldNumber1 = new JTextField();
		textFieldNumber2 = new JTextField();
		textFieldNumber3 = new JTextField();
		textFieldNumber4 = new JTextField();
		textFieldNumber5 = new JTextField();
		

		textFieldText1.setMinimumSize(new Dimension(170, 20));
		textFieldText2.setMinimumSize(new Dimension(170, 20));
		textFieldText3.setMinimumSize(new Dimension(170, 20));
		textFieldText4.setMinimumSize(new Dimension(170, 20));
		textFieldText5.setMinimumSize(new Dimension(170, 20));
		

		textFieldDate1.setMinimumSize(new Dimension(170, 20));
		textFieldDate2.setMinimumSize(new Dimension(170, 20));
		textFieldDate3.setMinimumSize(new Dimension(170, 20));
		textFieldDate4.setMinimumSize(new Dimension(170, 20));
		textFieldDate5.setMinimumSize(new Dimension(170, 20));
		

		textFieldNumber1.setMinimumSize(new Dimension(170, 20));
		textFieldNumber2.setMinimumSize(new Dimension(170, 20));
		textFieldNumber3.setMinimumSize(new Dimension(170, 20));
		textFieldNumber4.setMinimumSize(new Dimension(170, 20));
		textFieldNumber5.setMinimumSize(new Dimension(170, 20));
		


		textFieldText1.setBorder(new LineBorder(Color.GRAY));
		textFieldText2.setBorder(new LineBorder(Color.GRAY));
		textFieldText3.setBorder(new LineBorder(Color.GRAY));
		textFieldText4.setBorder(new LineBorder(Color.GRAY));
		textFieldText5.setBorder(new LineBorder(Color.GRAY));
		

		textFieldDate1.setBorder(new LineBorder(Color.GRAY));
		textFieldDate2.setBorder(new LineBorder(Color.GRAY));
		textFieldDate3.setBorder(new LineBorder(Color.GRAY));
		textFieldDate4.setBorder(new LineBorder(Color.GRAY));
		textFieldDate5.setBorder(new LineBorder(Color.GRAY));
		
		textFieldNumber1.setBorder(new LineBorder(Color.GRAY));
		textFieldNumber2.setBorder(new LineBorder(Color.GRAY));
		textFieldNumber3.setBorder(new LineBorder(Color.GRAY));
		textFieldNumber4.setBorder(new LineBorder(Color.GRAY));
		textFieldNumber5.setBorder(new LineBorder(Color.GRAY));
		
		
		panelOptionalFieldsDetail.add(textFieldText1, "cell 1 0,alignx left");
		panelOptionalFieldsDetail.add(textFieldText2, "cell 1 1,alignx left");
		panelOptionalFieldsDetail.add(textFieldText3, "cell 1 2,alignx left");
		panelOptionalFieldsDetail.add(textFieldText4, "cell 1 3,alignx left");
		panelOptionalFieldsDetail.add(textFieldText5, "cell 1 4,alignx left");
		
		panelOptionalFieldsDetail.add(textFieldDate1, "cell 3 0,alignx left");						
		panelOptionalFieldsDetail.add(textFieldDate2, "cell 3 1,alignx left");						
		panelOptionalFieldsDetail.add(textFieldDate3, "cell 3 2,alignx left");						
		panelOptionalFieldsDetail.add(textFieldDate4, "cell 3 3,alignx left");						
		panelOptionalFieldsDetail.add(textFieldDate5, "cell 3 4,alignx left");
		
		panelOptionalFieldsDetail.add(textFieldNumber1, "cell 5 0,alignx left");					
		panelOptionalFieldsDetail.add(textFieldNumber2, "cell 5 1,alignx left");						
		panelOptionalFieldsDetail.add(textFieldNumber3, "cell 5 2,alignx left");						
		panelOptionalFieldsDetail.add(textFieldNumber4, "cell 5 3,alignx left");
		panelOptionalFieldsDetail.add(textFieldNumber5, "cell 5 4,alignx left");
		
		scrollPaneActionDetail = new JScrollPane();
		scrollPaneActionDetail.setViewportView(panelActionDetails);
		tabbedPane.addTab(t.getLocalizedText("lblActionDetails"), null, scrollPaneActionDetail, null);
		tabbedPane.addTab(t.getLocalizedText("lblActionDetailsOptional"), null, panelOptionalFields, null);
		
		setEditableOptionalFields();
							

		getRootPaneExt().getContentPane().add(scrollPaneComments,BorderLayout.SOUTH);

		panelComments.setBackground(Color.WHITE);
		scrollPaneComments.setViewportView(panelComments);
		panelComments.setLayout(new MigLayout("", "[110px][306.00][1px,grow]", "[20px][129.00px][14px][31px][22px]"));

		lblComments.setFont(new Font("Tahoma", Font.BOLD, 16));
		panelComments.add(lblComments, "cell 0 0,alignx left,aligny center");

		tableComments = new JTable(modele);
		tableComments.setBorder(null);
		tableComments.getColumnModel().getColumn(1).setMaxWidth(80);
		tableComments.getColumnModel().getColumn(2).setMinWidth(0);
		tableComments.getColumnModel().getColumn(1).setMinWidth(0);
		tableComments.getColumnModel().getColumn(2).setMaxWidth(250);
		tableComments.getColumnModel().getColumn(1).setPreferredWidth(80);
		tableComments.getColumnModel().getColumn(2).setPreferredWidth(150);
		TableColumn col = tableComments.getColumnModel().getColumn(0);
		tableComments.getColumnModel().removeColumn(col);
		JScrollPane spcomment = new JScrollPane(tableComments);
		tableComments.addMouseListener(tableClick);
		spcomment.setPreferredSize(new Dimension(452, 140));
		panelComments.add(spcomment, "cell 0 1 3 1,grow");

		panelComments.add(lblAddComment, "cell 0 2,alignx left,aligny top");

		editorPaneNewComment.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelComments.add(editorPaneNewComment, "cell 0 3 3 1,grow");

		comboBoxResponsibleComment.setPreferredSize(new Dimension(110, 22));
		panelComments.add(comboBoxResponsibleComment, "cell 2 4,alignx right,aligny center");
		
		btnSubmit = new JButton("");
		btnSubmit.setAlignmentX(Component.LEFT_ALIGNMENT);
		btnSubmit.setBorder(null);
		btnSubmit.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("Add"))));
		btnSubmit.addMouseListener(submit);
		panelComments.add(btnSubmit, "cell 2 4");
		
		btnDelete = new JButton("");
		btnDelete.setAlignmentX(Component.LEFT_ALIGNMENT);
		btnDelete.setBorder(null);
		btnDelete.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("Delete"))));
		btnDelete.addMouseListener(deleteComment);
		panelComments.add(btnDelete, "cell 0 4");
		btnDelete.setVisible(false);
		listMeetingType = new MeetingTypeDB();
		listMeetingType.select(Session.userSequence);
		editorPaneActionDescription.requestFocusInWindow();
		
		for (MeetingType mt : listMeetingType.getFullList()) {
			comboBoxMeetingType.addItem(mt.getName());
			MeetingTypeMap.put(mt.getSequence(), mt.getName());
		}

		listSubSystem.select();		
		for (SubSystem s : listSubSystem.getFullList()) {
			comboBoxSubSystem.addItem(s.getSubsystemName());
			subSystemMap.put(s.getSequence(), s.getSubsystemName());

		}
		
		listActionType.select();
		for (ActionType at : listActionType.getFullList()) {
			comboBoxActionType.addItem(at.getActionTypeName());
			actionTypeMap.put(at.getSequence(), at.getActionTypeName());
		}		
		listUser.select(false);
		for (User u : listUser.getFullList()) {
			comboBoxResponsible.addItem(u.getLastName() + " "
					+ u.getFirstName());
			comboBoxResponsibleComment.addItem(u.getLastName() + " "
					+ u.getFirstName());;
			responsibleMap.put(u.getSequence(),
					u.getLastName() + " " + u.getFirstName());
		}
		
	
		
		if (this.hv.getSelectedMeeting().toString() != t.getLocalizedText("lblMeeting")){
			
			if (this.hv.getSelectedMeeting().toString() != "null" && !this.hv.getSelectedMeetingParent().toString().equals(t.getLocalizedText("lblMeeting"))){
				comboBoxMeetingType.setSelectedItem(this.hv.getSelectedMeetingParent());
				comboBoxMeeting.setSelectedItem(this.hv.getSelectedMeeting());
			}	else if (this.hv.getSelectedMeeting().toString() != "null" && this.hv.getSelectedMeetingParent().toString().equals(t.getLocalizedText("lblMeeting"))){
				comboBoxMeetingType.setSelectedItem(this.hv.getSelectedMeeting());
			}
		}
		
		
		if (this.hv.getSelectedSSComp().toString() != t.getLocalizedText("lblSubSystem")){
			
			if (this.hv.getSelectedSSComp().toString() != "null" && !this.hv.getSelectedSSCompParent().toString().equals(t.getLocalizedText("lblSubSystem"))){
				listSubSystem = new SubsystemDB();
				listSubSystem.selectBySSComponent(this.hv.getSelectedSSComp());
				comboBoxSubSystem.setSelectedItem(this.hv.getSelectedSSCompParent());
				comboBoxSSComponent.setSelectedItem(this.hv.getSelectedSSComp());
			}	else if (this.hv.getSelectedSSComp().toString() != "null" && this.hv.getSelectedSSCompParent().toString().equals(t.getLocalizedText("lblSubSystem"))){
				listSubSystem = new SubsystemDB();
				listSubSystem.selectBySubSystem(this.hv.getSelectedSSComp());
				comboBoxSubSystem.setSelectedItem(this.hv.getSelectedSSComp());
			}
		}
		
	}
//Mise à jour des détails de l'action
	private void updateAction() {
		MeetingDB meetDB = new MeetingDB();
		SSComponentDB sscompDB = new SSComponentDB();
		currentAction.setActionID(textFieldActionID.getText());
		if (comboBoxMeeting.getSelectedItem() != null)
		{
			if (comboBoxMeeting.getSelectedItem().toString().equals(""))
			{
				ProjectDB p = new ProjectDB();
				p.select(Session.projectSequence);
				currentAction.setSeqMeeting(p.getCurrentProject().getSequence());
			}
			else
			{
				Meeting meeting = meetDB.getMeetingByNames(comboBoxMeeting.getSelectedItem().toString(),comboBoxMeetingType.getSelectedItem().toString());
				if(meeting != null){
					currentAction.setSeqMeeting(meeting.getSequence());
					currentAction.setMeetingName(comboBoxMeeting.getSelectedItem().toString());
				}
			}
		}
		
		if (comboBoxSSComponent.getSelectedItem() != null)
		{
			if (comboBoxSSComponent.getSelectedItem().toString().equals(""))
			{
				ProjectDB p = new ProjectDB();
				p.select(Session.userSequence);
				currentAction.setseqSSComponent(p.getCurrentProject().getSequence());
				currentAction.setSScomponentName(comboBoxSSComponent.getSelectedItem().toString());
			}
			else
			{
				
				SSComponent sscompo = sscompDB.getSScomponentByNames(comboBoxSSComponent.getSelectedItem().toString(),comboBoxSubSystem.getSelectedItem().toString());
				if(sscompo != null){
					currentAction.setseqSSComponent(sscompo.getSequence());
					currentAction.setSScomponentName(comboBoxSSComponent.getSelectedItem().toString());
				}
			}
			
		}
		currentAction.setActionDesc(editorPaneActionDescription.getText());
		currentAction.setState(comboBoxState.getSelectedItem().toString());
		currentAction.setPriority(comboBoxPriority.getSelectedItem().toString().substring(4));

		currentAction.setOpenDate(form.format(openDate.getDate()));
		if (closeDate.getDate()!=null && currentAction.getState() != t.getLocalizedText("lblStateClosed") && currentAction.getCloseDate()!=""){
			closeDate.setDate(null);
			currentAction.setCloseDate("");
		}
		if (closeDate.getDate()!=null){
			currentAction.setCloseDate(form.format(closeDate.getDate()));
			currentAction.setState(t.getLocalizedText("lblStateClosed"));
		}
		if (currentAction.getState() == t.getLocalizedText("lblStateClosed") && closeDate.getDate()==null){
			currentAction.setCloseDate(form.format(Calendar.getInstance().getTime()));
		}
		
		if (pickerStart.getDate()!=null){
			currentAction.setInitialDueDate(form.format(pickerStart.getDate()));
		}
		if (pickerReview.getDate()!=null){
			currentAction.setReviewedDueDate(form.format(pickerReview.getDate()));
		}
		currentAction.setLastModified(LastModified.getText());
		if (!comboBoxResponsible.getSelectedItem().toString().equals("")) {
			currentAction.setseqResponsible(getKeyForValue(comboBoxResponsible.getSelectedItem().toString(), responsibleMap));
		} else {
			currentAction.setseqResponsible(-1);
		}
		currentAction.setseqActionType(getKeyForValue(comboBoxActionType.getSelectedItem().toString(), actionTypeMap));
		if (currentAction.getState().equals(t.getLocalizedText("lblStateOpened"))) {
			if (currentAction.getseqResponsible() > -1) {
				currentAction.setState(t.getLocalizedText("lblStateAssigned"));
			}
		}
		
		if (pickerStart.getDate() !=null){
				if(pickerReview.getDate() ==null){
				try {
					 oldInterv = Math.round(Calendar.getInstance().getTimeInMillis()- (FormatData.stringToDate2(currentAction.getOpenDate()).getTime()))/ (1000 * 60 * 60 * 24);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					System.err.println("updateAction 1 Ops : "+ e.getMessage());
				}
				try {
					newInterv = Math.round(pickerStart.getDate().getTime()- (FormatData.stringToDate2(currentAction.getOpenDate()).getTime()))/ (1000 * 60 * 60 * 24);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					System.err.println("updateAction 2 Ops : "+ e.getMessage());
				}
				}else{
					try {
						 oldInterv = Math.round(Calendar.getInstance().getTimeInMillis()- (FormatData.stringToDate2(currentAction.getOpenDate()).getTime()))/ (1000 * 60 * 60 * 24);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						System.err.println("updateAction 3 Ops : "+ e.getMessage());
					}
					try {
						newInterv = Math.round(pickerReview.getDate().getTime()- (FormatData.stringToDate2(currentAction.getOpenDate()).getTime()))/ (1000 * 60 * 60 * 24);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						System.err.println("updateAction 4 Ops : "+ e.getMessage());
					}
				}
					
		
			
			if (!(currentAction.getState().equals(t.getLocalizedText("lblStateClosed"))||currentAction.getState().equals(t.getLocalizedText("lblStateAdjourned")))){ // Si l'action n'est pas close
				if (oldInterv>2*newInterv/3){
					currentAction.setMaturity(t.getLocalizedText("lblBorder")); //Action proche de la deadline
				}
				else if (oldInterv>newInterv){
					currentAction.setMaturity(t.getLocalizedText("lblLate")); //Action en retard
					
				}
				else {
					currentAction.setMaturity(t.getLocalizedText("lblOK")); //Action dans les délais
				}
				}else{
					currentAction.setMaturity("-"); //Si l'action est close
			}	
			
		}
			
		
		currentAction.setDate01(textFieldDate1.getText());
		currentAction.setDate02(textFieldDate2.getText());
		currentAction.setDate03(textFieldDate3.getText());
		currentAction.setDate04(textFieldDate4.getText());
		currentAction.setDate05(textFieldDate5.getText());
		
		currentAction.setTxt01(textFieldText1.getText());
		currentAction.setTxt02(textFieldText2.getText());
		currentAction.setTxt03(textFieldText3.getText());
		currentAction.setTxt04(textFieldText4.getText());
		currentAction.setTxt05(textFieldText5.getText());
		currentAction.setNumber01(textFieldNumber1.getText());
		currentAction.setNumber02(textFieldNumber2.getText());
		currentAction.setNumber03(textFieldNumber3.getText());
		currentAction.setNumber04(textFieldNumber4.getText());
		currentAction.setNumber05(textFieldNumber5.getText());
		
	
		
	}

	public String getMeeting(){
		return comboBoxMeeting.getSelectedItem().toString();
	}
	
	private void updateComment() {
		currentComment.setCommentTxt(editorPaneNewComment.getText());
		currentComment.setseqAction(this.sequenceAction);
		currentComment.setseqUser(getKeyForValue(comboBoxResponsibleComment.getSelectedItem().toString(), responsibleMap));
	}
	
	private void updateFrameComment() {
		editorPaneNewComment.setText(currentComment.getCommentTxt());
		if (currentComment.getseqUser() == -1) {
			comboBoxResponsibleComment.setSelectedItem("");
		} else {
			comboBoxResponsibleComment.setSelectedItem(getValueForKey(currentComment.getseqUser(), responsibleMap));
		}
	}
	
	
	public void updateActionType(String val)
	{
		comboBoxActionType.removeAllItems();
				
		listActionType.select();
		comboBoxActionType.addItem("");
		for (ActionType at : listActionType.getFullList()) {
			comboBoxActionType.addItem(at.getActionTypeName());
			actionTypeMap.put(at.getSequence(), at.getActionTypeName());
		}
		comboBoxActionType.setSelectedItem(val);
	}

	public void updateSubSystem(String val)
	{
		comboBoxSubSystem.removeAllItems();
		
		listSubSystem.select();		
		comboBoxSubSystem.addItem("");
		for (SubSystem s : listSubSystem.getFullList()) {
			comboBoxSubSystem.addItem(s.getSubsystemName());
			subSystemMap.put(s.getSequence(), s.getSubsystemName());
		}
		comboBoxSubSystem.setSelectedItem(val);
	}
	
	public void updateSSComponent(String val)
	{
		if (comboBoxSubSystem.getSelectedItem() != null)
		{
			if (!comboBoxSubSystem.getSelectedItem().toString().equals(""))
			{
				comboBoxSSComponent.removeAllItems();
				listSSComponent.getFullList().clear();
				int seqSS = getKeyForValue(comboBoxSubSystem.getSelectedItem().toString(), subSystemMap);
				if (seqSS != -1) {
					listSSComponent.selectBySubSys(seqSS);
					for (SSComponent ss : listSSComponent.getFullList()) {
						comboBoxSSComponent.addItem(ss.getSsComponentName());
						ssComponentMap.put(ss.getSequence(),ss.getSsComponentName());
					}
					comboBoxSSComponent.setSelectedItem(val);
				}
			} else {
				comboBoxSSComponent.removeAllItems();
			}
		}
	}
	
	public void updateMeetingType(String val)
	{
		
				comboBoxMeetingType.removeAllItems();
				listMeetingType.select(Session.userSequence);
				comboBoxMeetingType.addItem("");
				for (MeetingType mt : listMeetingType.getFullList()) {
					comboBoxMeetingType.addItem(mt.getName());
					MeetingTypeMap.put(mt.getSequence(),mt.getName());
				}
					comboBoxMeetingType.setSelectedItem(val);

	}
	
	public void updateMeeting(String val)
	{
		if (comboBoxMeetingType.getSelectedItem() != null)
		{
			if (!comboBoxMeetingType.getSelectedItem().toString().equals(""))
			{
				comboBoxMeeting.removeAllItems();
				listMeeting.getFullList().clear();
				int seqMT = getKeyForValue(comboBoxMeetingType.getSelectedItem().toString(), MeetingTypeMap);
				if (seqMT != -1) {
					listMeeting.selectByMeetingType(seqMT);
					for (Meeting mt : listMeeting.getFullList()) {
						comboBoxMeeting.addItem(mt.getMeetingName());
						MeetingMap.put(mt.getSequence(),mt.getMeetingName());
					}
					comboBoxMeeting.setSelectedItem(val);
				}
			} else {
				comboBoxMeeting.removeAllItems();
			}
		}
	}
	
	public void updateOwner(String val)
	{
				comboBoxResponsible.removeAllItems();
				comboBoxResponsibleComment.removeAllItems();
					listUser = new UserDB();
					comboBoxResponsible.addItem("");
					listUser.select(false);
					for (User u : listUser.getFullList()) {
						comboBoxResponsible.addItem(u.getLastName() + " "
								+ u.getFirstName());
						comboBoxResponsibleComment.addItem(u.getLastName() + " "
								+ u.getFirstName());
						responsibleMap.put(u.getSequence(),
								u.getLastName() + " " + u.getFirstName());
					}
					
					comboBoxResponsible.setSelectedItem(val);
	}
	
	public Action getCurrentAction() {
		return currentAction;
	}
	
	//Mise à jour de la fenêtre détail des actions

	public void updateFrame(int seq) {
		listAction = new ActionDB();

		currentAction = listAction.selectBySeq(seq);
		listMeeting = new MeetingDB();
		if(currentAction.getSeqMeeting()>0){
			listMeeting.selectBySeq(currentAction.getSeqMeeting());
			currentMeeting = listMeeting.getMeetingbySeq(currentAction.getSeqMeeting());
		} else {
			currentMeeting= new Meeting();
		}
		textFieldActionID.setText(currentAction.getActionID());
		if (currentAction.getSeqMeeting() != 0) {	
			listMeeting = new MeetingDB();
			updateMeeting(currentAction.getMeetingName());
			listMeeting.selectBySeq(currentAction.getSeqMeeting());
			comboBoxMeetingType.setSelectedItem(getValueForKey(listMeeting.getFullList().get(0).getSeqMeetingType(),MeetingTypeMap));
			comboBoxMeeting.setSelectedItem(getValueForKey(currentAction.getSeqMeeting(), MeetingMap));
		}
		
		editorPaneActionDescription.setText(currentAction.getActionDesc());
		comboBoxState.setSelectedItem(t.getLocalizedText(currentAction.getState()));
		
		//Présélection de l'élément de la combobox de priorité
		if(t.getLocalizedText("High").toLowerCase().contains(currentAction.getPriority().toLowerCase())){
			comboBoxPriority.setSelectedItem(t.getLocalizedText("lblPriorityHigh"));
		}else if(t.getLocalizedText("Medium").toLowerCase().contains(currentAction.getPriority().toLowerCase())){
			comboBoxPriority.setSelectedItem(t.getLocalizedText("lblPriorityMedium"));
		}else if(t.getLocalizedText("Low").toLowerCase().contains(currentAction.getPriority().toLowerCase())){
			comboBoxPriority.setSelectedItem(t.getLocalizedText("lblPriorityLow"));
		}

		//openDate.setDate(currentAction.getOpenDate());
		LastModified.setText(currentAction.getLastModified());
		comboBoxResponsible.setSelectedItem(getValueForKey(
		currentAction.getseqResponsible(), responsibleMap));
		if (currentAction.getseqSSComponent() != 0) {
			listSSComponent = new SSComponentDB();
			updateSSComponent(currentAction.getSScomponentName());
			listSSComponent.selectBySeq(currentAction.getseqSSComponent());
			comboBoxSubSystem.setSelectedItem(getValueForKey(listSSComponent.getFullList().get(0).getSubsystemSequence(),subSystemMap));
			comboBoxSSComponent.setSelectedItem(getValueForKey(currentAction.getseqSSComponent(), ssComponentMap));
		}	
		comboBoxActionType.setSelectedItem(getValueForKey(currentAction.getseqActionType(), actionTypeMap));
		listMeeting = new MeetingDB();
		if(currentAction.getSeqMeeting()>0){
			listMeeting.selectBySeq(currentAction.getSeqMeeting());
			currentMeeting = listMeeting.getFullList().get(0);
		} else {
			currentMeeting= new Meeting();
		}

		textFieldDate1.setText(currentAction.getDate01());
		textFieldDate2.setText(currentAction.getDate02());
		textFieldDate3.setText(currentAction.getDate03());
		textFieldDate4.setText(currentAction.getDate04());
		textFieldDate5.setText(currentAction.getDate05());
		
		textFieldText1.setText(currentAction.getTxt01());
		textFieldText2.setText(currentAction.getTxt02());
		textFieldText3.setText(currentAction.getTxt03());
		textFieldText4.setText(currentAction.getTxt04());
		textFieldText5.setText(currentAction.getTxt05());

		textFieldNumber1.setText(currentAction.getNumber01());
		textFieldNumber2.setText(currentAction.getNumber02());
		textFieldNumber3.setText(currentAction.getNumber03());
		textFieldNumber4.setText(currentAction.getNumber04());
		textFieldNumber5.setText(currentAction.getNumber05());
	
		hv.addWindowFocusListener (clickhomeview);
	}

	private int getKeyForValue(String value, TreeMap<Integer, String> map) {
		for (Entry<Integer, String> entry : map.entrySet()) {
			if (entry.getValue().equals(value)) {
				return entry.getKey();
			}
		}
		return -1;
	}

	public void setComboBoxSubSystem(JComboBox<String> comboBoxSubSystem) {
		this.comboBoxSubSystem = comboBoxSubSystem;
	}

	public JComboBox<String> getComboBoxSubSystem() {
		return comboBoxSubSystem;
	}
	
	public JComboBox<String> getComboBoxMeetingType() {
		return comboBoxMeetingType;
	}

	private String getValueForKey(int key, TreeMap<Integer, String> map) {
		for (Entry<Integer, String> entry : map.entrySet()) {
			if (entry.getKey().equals(key)) {
				return entry.getValue();
			}
		}
		return "";
	}
	private boolean checkValues()
	{
		boolean checkValues = true;
		if (editorPaneActionDescription.getText().length() > 512)
		{
			//editorPaneActionDescription.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//editorPaneActionDescription.setBackground(Color.white);
		}
		if (comboBoxSSComponent.getSelectedItem() != null){
			if (comboBoxSSComponent.getSelectedItem().toString().startsWith(">")){
				//comboBoxSSComponent.setBackground(Color.getHSBColor(255, 255, 50));
				checkValues = false;
			} else {
				//comboBoxSSComponent.setBackground(Color.getHSBColor(255, 255, 255));
			}
		}
		if (comboBoxMeeting.getSelectedItem() != null){
			if (comboBoxMeeting.getSelectedItem().toString().startsWith(">")){
				//comboBoxMeeting.setBackground(Color.getHSBColor(255, 255, 50));
				checkValues = false;
			} else {
				//comboBoxMeeting.setBackground(Color.getHSBColor(255, 255, 255));
			}
		}
		if (pickerStart.getDate()!=null){
		if (!FormatData.isDate(form.format(pickerStart.getDate())))
		{
			
			//pickerStart.setForeground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//pickerStart.setForeground(Color.getHSBColor(255, 255, 255));
		}
		}
		if (pickerReview.getDate()!=null){
			
			if (!FormatData.isDate(form.format(pickerReview.getDate())))
			{
				//pickerReview.setForeground(Color.getHSBColor(255, 255, 50));
				checkValues = false;
			} else {
				//pickerReview.setForeground(Color.getHSBColor(255, 255, 255));
			}
		}
		if (openDate.getDate()!=null){
			if (!FormatData.isDate(form.format(openDate.getDate())))
			{
				//openDate.setForeground(Color.getHSBColor(255, 255, 50));
				checkValues = false;
			} else {
				//openDate.setBackground(Color.getHSBColor(255, 255, 255));
			}
		}		
		if (!FormatData.isDate(textFieldDate1.getText()))
		{
			//textFieldDate1.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldDate1.setBackground(Color.white);
		}
		
		if (!FormatData.isDate(textFieldDate2.getText()))
		{
			//textFieldDate2.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldDate2.setBackground(Color.white);
		}
		
		if (!FormatData.isDate(textFieldDate3.getText()))
		{
			//textFieldDate3.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldDate3.setBackground(Color.white);
		}
		
		if (!FormatData.isDate(textFieldDate4.getText()))
		{
			//textFieldDate4.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldDate4.setBackground(Color.white);
		}
		
		if (!FormatData.isDate(textFieldDate5.getText()))
		{
			//textFieldDate5.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldDate5.setBackground(Color.white);
		}
		
		if (!FormatData.isNumber(textFieldNumber1.getText()))
		{
			//textFieldNumber1.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldNumber1.setBackground(Color.white);
		}
		
		if (!FormatData.isNumber(textFieldNumber2.getText()))
		{
			//textFieldNumber2.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldNumber2.setBackground(Color.white);
		}
		
		if (!FormatData.isNumber(textFieldNumber3.getText()))
		{
			//textFieldNumber3.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldNumber3.setBackground(Color.white);
		}
		
		if (!FormatData.isNumber(textFieldNumber4.getText()))
		{
			//textFieldNumber4.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldNumber4.setBackground(Color.white);
		}
		
		if (!FormatData.isNumber(textFieldNumber5.getText()))
		{
			//textFieldNumber5.setBackground(Color.getHSBColor(255, 255, 50));
			checkValues = false;
		} else {
			//textFieldNumber5.setBackground(Color.white);
		}
		
		if (checkValues) {
			lblError.setText("");
		} else {
			lblError.setText(t.getLocalizedText("errorFormat"));
		}
		return checkValues;
	}
	

	public void refresh() {
		modele = new JTableModelComment(sequenceAction);
		tableComments.setModel(modele);
		TableColumn col = tableComments.getColumnModel().getColumn(0);
		tableComments.getColumnModel().removeColumn(col);
		tableComments.getColumnModel().getColumn(0).setMaxWidth(80);
		tableComments.getColumnModel().getColumn(1).setMinWidth(0);
		tableComments.getColumnModel().getColumn(0).setMinWidth(0);
		tableComments.getColumnModel().getColumn(1).setMaxWidth(250);
		tableComments.getColumnModel().getColumn(0).setPreferredWidth(80);
		tableComments.getColumnModel().getColumn(1).setPreferredWidth(150);
	}
	public ActionDetailsView getThisView(){
		return this;
	}
	public JComboBox<String> getcomboBoxResponsible(){
		return comboBoxResponsible;
	}
	public JComboBox<String> getComboBoxResponsibleComment(){
		return comboBoxResponsibleComment;
	}
	public TreeMap<Integer, String> getResponsibleMap(){
		return responsibleMap;
	}
	public UserDB getListUser(){
		return listUser;
	}
	
	//Gestion des colonnes
	public void setEditableOptionalFields()
	{

		cm = new ColumnManager(true);
		if (cm.GetColumn("text01").getIndex() == -1) {
			textFieldText1.setEditable(false);
		}
		if (cm.GetColumn("text02").getIndex() == -1) {
			textFieldText2.setEditable(false);
		}
		if (cm.GetColumn("text03").getIndex() == -1) {
			textFieldText3.setEditable(false);
		}
		if (cm.GetColumn("text04").getIndex() == -1) {
			textFieldText4.setEditable(false);
		}
		if (cm.GetColumn("text05").getIndex() == -1) {
			textFieldText5.setEditable(false);
		}
		

		if (cm.GetColumn(Constants.DATE_1).getIndex() == -1) {
			textFieldDate1.setEditable(false);
		}
		if (cm.GetColumn(Constants.DATE_2).getIndex() == -1) {
			textFieldDate2.setEditable(false);
		}
		if (cm.GetColumn(Constants.DATE_3).getIndex() == -1) {
			textFieldDate3.setEditable(false);
		}
		if (cm.GetColumn(Constants.DATE_4).getIndex() == -1) {
			textFieldDate4.setEditable(false);
		}
		if (cm.GetColumn(Constants.DATE_5).getIndex() == -1) {
			textFieldDate5.setEditable(false);
		}
		
		if (cm.GetColumn(Constants.NUMBER_1).getIndex() == -1) {
			textFieldNumber1.setEditable(false);
		}
		if (cm.GetColumn(Constants.NUMBER_2).getIndex() == -1) {
			textFieldNumber2.setEditable(false);
		}
		if (cm.GetColumn(Constants.NUMBER_3).getIndex() == -1) {
			textFieldNumber3.setEditable(false);
		}
		if (cm.GetColumn(Constants.NUMBER_4).getIndex() == -1) {
			textFieldNumber4.setEditable(false);
		}
		if (cm.GetColumn(Constants.NUMBER_5).getIndex() == -1) {
			textFieldNumber5.setEditable(false);
		}
		
	}
	

	/*************************************************************************
	 * Listner
	 *************************************************************************/
	WindowAdapter closeWindow = new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent arg0) {
			
			if (newAction) {
				listAction = new ActionDB();
				listAction.deleteByActionID(textFieldActionID.getText());
			}
			setVisible(false);
			ActionDetailsView.this.hv.setEnabled(true);
			ActionDetailsView.this.hv.toFront();
		}
	};

	MouseAdapter cancel = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			if (newAction) {
				listAction = new ActionDB();
				listAction.deleteByActionID(textFieldActionID.getText());
			}
			setVisible(false);
			ActionDetailsView.this.hv.setEnabled(true);
			ActionDetailsView.this.hv.toFront();
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(
					t.getLocalizedText("CancelS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(
					t.getLocalizedText("Cancel"))));
		}
	};
	
	ActionListener choseSubSystem = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			if (comboBoxSubSystem.getSelectedItem() != null)
			{
				if (!comboBoxSubSystem.getSelectedItem().toString().equals(""))
				{
					comboBoxSSComponent.removeAllItems();
					listSSComponent.getFullList().clear();
					int seqSS = getKeyForValue(comboBoxSubSystem.getSelectedItem().toString(), subSystemMap);
					if (seqSS != -1) {
						listSSComponent.selectBySubSys(seqSS);
						for (SSComponent ssc : listSSComponent.getFullList()) {
							comboBoxSSComponent.addItem(ssc.getSsComponentName());
							ssComponentMap.put(ssc.getSequence(),ssc.getSsComponentName());
						}
						comboBoxSSComponent.setSelectedIndex(0);
					}
				} else {
					comboBoxSSComponent.removeAllItems();
				}
				
			}
		}
	};
	
	ActionListener choseMeetingType = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			if (comboBoxMeetingType.getSelectedItem() != null)
			{
				if (!comboBoxMeetingType.getSelectedItem().toString().equals(""))
				{
					comboBoxMeeting.removeAllItems();
					listMeeting.getFullList().clear();
					int seqMT = getKeyForValue(comboBoxMeetingType.getSelectedItem().toString(), MeetingTypeMap);
					if (seqMT != -1) {
						listMeeting.selectByMeetingType(seqMT);
						for (Meeting mt : listMeeting.getFullList()) {
							comboBoxMeeting.addItem(mt.getMeetingName());
							MeetingMap.put(mt.getSequence(),mt.getMeetingName());
						}
						comboBoxMeeting.setSelectedIndex(0);
					}
				} else {
					comboBoxMeeting.removeAllItems();
				}
				
			}
		}
	};
	WindowFocusListener  clickhomeview = new  WindowFocusListener () {

		@Override
		public void windowGainedFocus(WindowEvent arg0) {
			// TODO Auto-generated method stub
			toFront();
		}

		@Override
		public void windowLostFocus(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}



	};

	
	MouseAdapter btnReturnAction = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			if (checkValues())
			{

				//Sauvegarde du tri du tableau des actions
				int indexColTri = ActionDetailsView.this.hv.getTableActList().getSortedColumnIndex();
				SortOrder sort = ActionDetailsView.this.hv.getTableActList().getSortOrder(indexColTri);
				ActionDetailsView.this.hv.toFront();
				SSComponent currentComponent = new SSComponent();
				
				
				currentAction.setLastModified(FormatData.getDateNow());
				listAction = new ActionDB();
				updateAction();

				if (currentAction.getSeqMeeting() != currentMeeting.getSequence())
				{
					currentMeeting = listMeeting.getMeetingbySeq(currentAction.getSeqMeeting());
					currentAction.setActionID(listAction.getLastActionID(currentMeeting));
				}
				currentMeeting = listMeeting.getMeetingbySeq(currentAction.getSeqMeeting());
				currentComponent = listSSComponent.selectBySeq(currentAction.getseqSSComponent());
				if (!editorPaneNewComment.getText().isEmpty()){
					updateComment();
					if (currentComment.getSequence()==0) {
						listComment.insert(currentComment);
					} else {
						listComment.update(currentComment);
					}
					modele = new JTableModelComment(sequenceAction);
					tableComments.setModel(modele);
					currentComment = new Comment();
					updateFrameComment();
					//refresh();
				}
				currentAction.Clean();

				
				listAction.update(currentAction);
				setVisible(false);

				if(ActionDetailsView.this.hv.getModele().getTypeTreeClick() != 0 && ActionDetailsView.this.hv.getModele().getSequenceTreeClick() !=0){
					ActionDetailsView.this.hv.setModele(new JTableModel(ActionDetailsView.this.hv.getModele().getSequenceTreeClick(), ActionDetailsView.this.hv.getModele().getTypeTreeClick()));
				} else {
					ActionDetailsView.this.hv.setModele(new JTableModel());
				}

				
				ActionDetailsView.this.hv.refresh(ActionDetailsView.this.hv.getModele());
				editorPaneActionDescription.setBackground(null);
				pickerStart.setBackground(null);
				pickerReview.setBackground(null);
				ActionDetailsView.this.hv.setEnabled(true);
				//ActionDetailsView.this.hv.refreshTree();
				
				//On fixe le tri enregistrer et on l'applique au nouveau tableau
				if(indexColTri != -1){
					hv.getTableActList().setSortOrder(indexColTri, sort);
				}

			}
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(
					t.getLocalizedText("ValidateS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(
					t.getLocalizedText("Validate"))));
		}
	};
	
	MouseAdapter addOwner = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			JXFrame managerView = new CreateManagerView(false, ActionDetailsView.this);
			setEnabled(false);
			managerView.setVisible(true);
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusBS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusB"))));
		}
	};
	
	MouseAdapter addMeet = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			JXFrame addMeeting = new AddMeetingBox(ActionDetailsView.this.hv, ActionDetailsView.this);
			setEnabled(false);
			addMeeting.setVisible(true);
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusBS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusB"))));
		}
	};
	
	MouseAdapter addActionType = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			JFrame addActionType = new AddActionTypeBox(ActionDetailsView.this);
			setEnabled(false);
			addActionType.setVisible(true);
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusBS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusB"))));
		}
	};
	
	
	MouseAdapter addSubSysComponent = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			JXFrame addSSComponent = new AddSSComponentBox(ActionDetailsView.this.hv,ActionDetailsView.this);
			setEnabled(false);
			addSSComponent.setVisible(true);
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusBS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("PlusB"))));
		}
	};
	
	MouseAdapter submit = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			
			if (!editorPaneNewComment.getText().isEmpty()){
				updateComment();
				if (currentComment.getSequence()==0) {
					listComment.insert(currentComment);
				} else {
					listComment.update(currentComment);
				}
				modele = new JTableModelComment(sequenceAction);
				tableComments.setModel(modele);
				currentComment = new Comment();
				updateFrameComment();
			}

			refresh();
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass()
					.getResource(t.getLocalizedText("AddS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			JButton source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("Add"))));
		}
	};
	MouseAdapter tableClick = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {				
			btnDelete.setVisible(true);
			currentComment = listComment.selectBySeq(Integer.parseInt(modele.getValueAt(tableComments.getSelectedRow(), 0).toString()));
			updateFrameComment();
		}
	};
	
	
	MouseAdapter deleteComment = new MouseAdapter() {
		@Override
		public void mouseReleased(MouseEvent e) {
			
			if (currentComment.getSequence() != 0) {
				listComment.delete(currentComment.getSequence());
			}
			currentComment = new Comment();
			updateFrameComment();
			refresh();
			btnDelete.setVisible(false);
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("DeleteS"))));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			source = (JButton) e.getSource();
			source.setIcon(new ImageIcon(getClass().getResource(t.getLocalizedText("Delete"))));
		}
	};
	private JScrollPane scrollPaneTitle;
	private JComboBox<String> comboBoxMeetingType;
	private JLabel lblMeetingType;
	private JComboBox<String> comboBoxMeeting;
	private JButton btnSubmit;
	private JButton btnDelete;
	private JTabbedPane tabbedPane;
	private JPanel panelOptionalFieldsDetail;
	private JLabel lblText1;
	private JLabel lblText2;
	private JLabel lblText3;
	private JLabel lblText4;
	private JLabel lblText5;
	private JLabel lblDate1;
	private JLabel lblDate2;
	private JLabel lblDate3;
	private JLabel lblDate4;
	private JLabel lblDate5;
	private JLabel lblNumber1;
	private JLabel lblNumber2;
	private JLabel lblNumber3;
	private JLabel lblNumber4;
	private JLabel lblNumber5;
	private JTextField textFieldText1;
	private JTextField textFieldText2;
	private JTextField textFieldText3;
	private JTextField textFieldText4;
	private JTextField textFieldText5;
	private JTextField textFieldDate1;
	private JTextField textFieldDate2;
	private JTextField textFieldDate3;
	private JTextField textFieldDate4;
	private JTextField textFieldDate5;
	private JTextField textFieldNumber1;
	private JTextField textFieldNumber2;
	private JTextField textFieldNumber3;
	private JTextField textFieldNumber4;
	private JTextField textFieldNumber5;
	private JPanel panelOptionalFields;
	private JTextArea textAreaExplanation;
	private JEditorPane editorPaneActionDescription;
	private JScrollPane scrollPaneActionDetail;
}
